package web.controller.sys;

import com.github.pagehelper.PageInfo;
import framework.vo.L;
import framework.vo.R;
import framework.vo.ResultInfo;
import framework.vo.ResultList;
import io.swagger.annotations.*;
import java.util.List;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import system.dto.sys.SysFuncAdd;
import system.dto.sys.SysFuncQuery;
import system.dto.sys.SysFuncResult;
import system.dto.sys.SysFuncUpdate;
import system.entity.SysFunc;
import system.service.sys.SysFuncService;

@RestController
@RequestMapping("/sys/func")
@Api(tags = "功能表")
public class SysFuncController {
    @Autowired
    private SysFuncService sysFuncService;

    @ApiOperation("添加功能表")
    @PostMapping("/add")
    public ResultInfo<String> add(@ModelAttribute SysFuncAdd add) {
        java.util.Date now = new java.util.Date();
        SysFunc param = new SysFunc();
        BeanUtils.copyProperties(add, param);
        param.setCreateTime(now);
        param.setUpdateTime(now);
        sysFuncService.add(param);
        return R.ok(param.getId());
    }

    @ApiOperation("删除功能表")
    @PostMapping("/del")
    public ResultInfo<Integer> del(@RequestParam("ids") List<String> ids) {
        Integer deleted = sysFuncService.deleteByIds(ids);
        return R.ok(deleted);
    }

    @ApiOperation("更新功能表")
    @PostMapping("/edit")
    public ResultInfo<Integer> edit(@ModelAttribute SysFuncUpdate update) {
        java.util.Date now = new java.util.Date();
        SysFunc param = new SysFunc();
        BeanUtils.copyProperties(update, param);
        param.setUpdateTime(now);
        Integer updated = sysFuncService.updateBody(param);
        return R.ok(updated);
    }

    @ApiOperation("查看功能表")
    @GetMapping("/info")
    public ResultInfo<SysFuncResult> info(@RequestParam("id") String id) {
        SysFuncQuery query = new SysFuncQuery();
        query.setId(id);
        SysFuncResult info = sysFuncService.listQueryOne(query);
        return R.ok(info);
    }

    @ApiOperation("功能表列表")
    @GetMapping("/list")
    public ResultList<SysFuncResult> list(@ModelAttribute SysFuncQuery param, @RequestParam(value = "pageIndex", defaultValue = "1") Integer pageIndex, @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageInfo<SysFuncResult> info = sysFuncService.listQuery(param, pageIndex, pageSize);
        return L.ok(info);
    }
}